var selectedDataRow = '';
var vueObj = new Vue({
    el: "#vue",
    data: {
        logObj: defLogInfo
    }
});
var isInit = true;

$(function () {
    window.actionEvents = {
        'click .infoView': function(e, value, row, index) {
            //编辑操作
            selectedDataRow = row;
            openInfoOrderPage();
        },
        'click .isvInfoView': function(e, value, row, index) {
            //编辑操作
            selectedDataRow = row;
            openCommonIsvPage(row.isvPid, 'checkOrder');
        },
    }
    initTextSearch("#isvName",
        basePath + 'checkContent/getIsvData?t='+new Date().getTime()+'&isvName=',
        ['isvPid', 'isvName'],
        {'isvPid':'服务商PID', 'isvName':'服务商名称'},
        'isvPid',
        'isvName',
        true,
        selectIsvValue,
        noSelectIsvValue,
        false);
    laydate.render({
        elem: '#timeInterval'
        ,type: 'datetime'
        ,range: true //或 range: '~' 来自定义分割字符
        // ,value: dateFtt("yyyy-MM-dd hh:mm:ss", preDate) + ' - ' + dateFtt("yyyy-MM-dd hh:mm:ss", curDate)
        //js赋值重置失效，改为就是怕、页面赋值
        ,isInitValue: true //是否允许填充初始值，默认为 true
    });
});

function selectIsvValue(data) {
    if (!data || !data.isvPid) {
        return;
    }
    $('#isvPid').val(data.isvPid);
}

function noSelectIsvValue() {
    $('#isvPid').val('');
}

function doRefresh() {
    selectedDataRow = '';
    var searchKey = $('#searchKey').val();
    var result = $('#result').val();
    var isvPid = $('#isvPid').val();
    var dataStatus = $('#dataStatus').val();
    var checkType = $('#checkType').val();
    var contentType = $('#contentType').val();
    var isFree = $('#isFree').val();
    var isPlatformCharge = $('#isPlatformCharge').val();
    var gmtStart = '';
    var gmtEnd = '';
    var timeInterval = $("#timeInterval").val();
    if(timeInterval){
        var dates = timeInterval.split(' - ');
        if(dates && dates.length >1){
            gmtStart = dates[0];
            gmtEnd = dates[1];
        }
    }
    $('#dataTable').bootstrapTable('refresh', {
        url: basePath + 'checkContent/pageFindQueryData?t=' + new Date().getTime(),
        query: {
            searchKey : searchKey,
            isvPid : isvPid,
            checkType : checkType,
            dataStatus : dataStatus,
            result : result,
            contentType : contentType,
            isFree : isFree,
            isPlatformCharge : isPlatformCharge,
            beginTimeStr : gmtStart,
            endTimeStr : gmtEnd,
        },
    });
}

function getParams(params) {
    var searchKey = $('#searchKey').val();
    var isvPid = $('#isvPid').val();
    var result = $('#result').val();
    var dataStatus = $('#dataStatus').val();
    var checkType = $('#checkType').val();
    var contentType = $('#contentType').val();
    var isFree = $('#isFree').val();
    var isPlatformCharge = $('#isPlatformCharge').val();
    var gmtStart = '';
    var gmtEnd = '';
    var timeInterval = $("#timeInterval").val();
    if(timeInterval){
        var dates = timeInterval.split(' - ');
        if(dates && dates.length >1){
            gmtStart = dates[0];
            gmtEnd = dates[1];
        }
    }
    var pageSize = params.pageSize;
    var pageNo = params.pageNumber;
    if (isInit) {
        isInit = false;
        pageSize = defLogInfo.pageSize ? defLogInfo.pageSize : params.pageSize;
        pageNo = defLogInfo.pageNo ? defLogInfo.pageNo : params.pageNumber;
    }
    return {
        searchKey : searchKey,
        isvPid : isvPid,
        result : result,
        dataStatus : dataStatus,
        checkType : checkType,
        contentType : contentType,
        isFree : isFree,
        isPlatformCharge : isPlatformCharge,
        beginTimeStr : gmtStart,
        endTimeStr : gmtEnd,
        pageSize : pageSize,
        pageNo : pageNo
    };
}

function getSearchParam() {
    var tableOptions = $('#dataTable').bootstrapTable('getOptions', null);
    var param1 = $('#searchForm').serialize().replace(/&/g, ',');
    return param1 + ',pageNo=' + tableOptions.pageNumber + ',pageSize=' + tableOptions.pageSize  + ',isQueryExist=' + defLogInfo.isCheckExist;
}

function openInfoOrderPage() {
    if (!selectedDataRow || selectedDataRow == '') {
        toastr.error(common_no_choose_msg.format("查看"));
        return;
    }
    if (!selectedDataRow.id || selectedDataRow.id == '') {
        toastr.error('所选数据存在问题，请刷新页面重试');
        return;
    }
    window.location.href = basePath + 'checkContent/checkContentInfoPage?&id=' + selectedDataRow.id +
        '&type=info&t=' + new Date().getTime() + '&searchParam=' + getSearchParam() + '&contentType=' + selectedDataRow.contentType;
}

//------------------------------------------------------------------------列表数据初始化

function formatCheckType(value, row, index) {
    if (checkTypeMap) {
        return checkTypeMap[value];
    }
    return value;
}

function formatContentType(value, row, index) {
    if (contentTypeMap) {
        return contentTypeMap[value];
    }
    return value;
}

function formatIsFree(value, row, index) {
    if (yesOrNoMap) {
        return yesOrNoMap[value];
    }
    return value;
}

function formatIsPlatformCharge(value, row, index) {
    if (yesOrNoMap) {
        return yesOrNoMap[value];
    }
    return value;
}

function formatResult(value, row, index) {
    if (value == 'pass') {
        return '通过';
    }
    if (value == 'unpass') {
        return '未通过';
    }
    return value;
}

//------------------------------------------------------------------------列表选中事件
//上边选中事件
$("#dataTable").on("click-row.bs.table",function(e,row,ele){
    $("#dataTable .success").removeClass("success");
    $(ele).addClass("success");
    selectedDataRow = row;
});
